-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reading/writing text envelopes from pipes #4384
Conversation
1ba57d6
to
ec5063c
Compare
Previously the functions to read text envelopes used `readFile` from Data.ByteString. Unfortunately, that doesn't work with pipes, so we've switched to a function that does. Additionally, on unix based systems, we've changed how writing to an owned file works. Previously a new file was created (and since we created it, we must own it) and then copied into place. Unfortunately this doesn't work with symlinks, fifos, unix sockets or anything else that isn't a "normal" file. What we do now is grab the file descriptor, call fchown on it, which sets us as the owner (or errors out if we can't do that), and then write to the file.
ec5063c
to
e8c5317
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! One question
bracketOnError | ||
(openFd path WriteOnly (Just ownerModes) defaultFileFlags) | ||
closeFd | ||
(\fd -> setFdOwnerAndGroup fd user (-1) >> pure fd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why -1
for the group id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFdOwnerAndGroup
is a thin wrapper over fchown
, and has kept the behaviour of the original (-1
for "do not change") instead of changing the type to be a more idiomatic Haskell Maybe Int
.
bors r+ |
Build succeeded: |
Previously the functions to read text envelopes used
readFile
fromData.ByteString. Unfortunately, that doesn't work with pipes, so we've
switched to a function that does.
Additionally, on unix based systems, we've changed how writing to an
owned file works. Previously a new file was created (and since we
created it, we must own it) and then copied into place. Unfortunately
this doesn't work with symlinks, fifos, unix sockets or anything else
that isn't a "normal" file. What we do now is grab the file descriptor,
call fchown on it, which sets us as the owner (or errors out if we can't
do that), and then write to the file.
Fixes #4235